﻿@model SiteMapNode
@using Urs.Core
@using Urs.Data.Domain.Localization
@using Urs.Framework.Menu
@using Microsoft.AspNetCore.Routing
@inject IWorkContext workContext
@{
    string urlHelper(string modelUrl, string controllerName, string actionName, RouteValueDictionary routeValues)
    {
        string url = null;
        if (!string.IsNullOrEmpty(controllerName) && !string.IsNullOrEmpty(actionName))
        {
            url = Url.Action(actionName, controllerName, routeValues, null, null);
        }
        else if (!string.IsNullOrEmpty(modelUrl))
        {
            url = modelUrl.StartsWith("~/", StringComparison.Ordinal) ? Url.Content(modelUrl) : modelUrl;
        }
        return url;
    }
}
@{
    var href = urlHelper(Model.Url, Model.ControllerName, Model.ActionName, Model.RouteValues);
    if (!String.IsNullOrEmpty(href))
    {
        <li data-name="@Model.SystemName" class="layui-nav-item layui-nav-itemed layui-this">
            <a href="javascript:;" lay-href="@href" lay-tips="@Model.Title" lay-direction="2">
                <i class="layui-icon @Url.Content(Model.IconClass)"></i>
                <cite>@Model.Title</cite>
            </a>
        </li>
    }
    else
    {
        <li data-name="@Model.SystemName" class="layui-nav-item">
            <a href="javascript:;" lay-tips="@Model.Title" lay-direction="2">
                @if (!String.IsNullOrEmpty(Model.IconClass))
                {
                    <text>
                        <i class="layui-icon @Url.Content(Model.IconClass)"></i>
                    </text>
                }
                <cite>@Model.Title</cite>
            </a>
            @{ var childNodes = Model.ChildNodes.Where(x => x.Visible).ToList(); }
            @if (childNodes.Any())
            {
                <dl class="layui-nav-child">
                    @foreach (var childItem in childNodes)
                    {
                        var subItems = childItem.ChildNodes.Where(x => x.Visible).ToList();
                        <dd>
                            @if (subItems.Any())
                            {
                                <a href="javascript:;">@childItem.Title</a>
                                <dl class="layui-nav-child">
                                    @foreach (var item in subItems)
                                    {
                                        <dd><a lay-href="@urlHelper(item.Url, item.ControllerName, item.ActionName, item.RouteValues)">@item.Title</a></dd>
                                    }
                                </dl>
                            }
                            else
                            {
                                <a href="javascript:;" lay-href="@urlHelper(childItem.Url, childItem.ControllerName, childItem.ActionName, childItem.RouteValues)">@childItem.Title</a>
                            }
                        </dd>
                    }
                </dl>
            }
        </li>
    }
}
